package com.johnny.springcloud.service;

import com.johnny.springcloud.util.IdGeneratorSnowflake;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

@Service
public class OrderService {
    @Autowired
    private IdGeneratorSnowflake idGeneratorSnowflake;

    public String getIDBySnowFlake() {

        ExecutorService threadPool = Executors.newFixedThreadPool(5);  //线程池

        for (int i = 1; i <= 20; i++) {
            threadPool.submit(() -> {
                System.out.println(idGeneratorSnowflake.snowflakeId());
            });
        }
        threadPool.shutdown();

        return "hello snowflake";
    }
}
